import { Button, Input } from "antd";
import React, { useState } from "react";
import md5 from "md5";
import instance from "../../api/request";
const appKey = "0c03b7d88ce36a25";
const appMiyao = "He1zJjsEUnsqf9DePmFaCjo50MN2jE2Z";
function Index() {
  const [data, setData] = useState();
  const [list, setList] = useState();
  const fy = async () => {
    const salt = Date.now().toString();
    const sign = md5(appKey + data + salt + appMiyao);

    const params = {
      q: data,
      from: "auto",
      to: "auto",
      appKey,
      salt,
      sign,
    };
    const res = await instance.get("/youdao/api", {
      params,
    });

    console.log(res);
    setList(res.data.translation[0]);
  };

  return (
    <div>
      <Input
        onChange={(e) => {
          setData(e.target.value);
        }}
      ></Input>
      <Button onClick={() => fy()}>翻译</Button>
      <div>{list}</div>
    </div>
  );
}

export default Index;
